package com.xz.questions.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.hutool.Hutool;
import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.fastjson.JSONObject;
import com.xz.questions.common.BaseResponse;
import com.xz.questions.common.ErrorCode;
import com.xz.questions.common.ResultUtils;
import com.xz.questions.constant.FileConstant;
import com.xz.questions.constant.UserConstant;
import com.xz.questions.exception.BusinessException;
import com.xz.questions.manager.CosManager;
import com.xz.questions.model.dto.file.UploadFileRequest;
import com.xz.questions.model.entity.User;
import com.xz.questions.model.enums.FileUploadBizEnum;
import com.xz.questions.service.ChatService;
import com.xz.questions.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * ai 接口
 */
@RestController
@RequestMapping("/ai")
@Slf4j
public class AiController {


    @Resource
    private ChatService chatService;


    @RequestMapping("/answer")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<String> answer(@RequestBody String question) throws NoApiKeyException, InputRequiredException {

        String generationResult = chatService.chatAi(question);

        return ResultUtils.success(generationResult);
    }

}
